package Chapter6.many_to_many;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

@Entity
public class Teacher implements Serializable {
	private static final long serialVersionUID = 1L;
	private long id;
	private String name;
	private Set<School> schools;

	public Teacher(String name) {
		this.name = name;
		this.schools = new HashSet<School>();
	}

	public Teacher() {
	}

	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "Zschool_teacher", joinColumns = { @JoinColumn(name = "teacherID") }, inverseJoinColumns = { @JoinColumn(name = "Schoo_ID") })
	public Set<School> getSchools() {
		return schools;
	}

	public void setSchools(Set<School> schools) {
		this.schools = schools;
	}

}
